#!/bin/sh
# Build SD card image

BOARD_ID="${1}" # For example "bananapi"
CHIP_ID="${2}" # For example "allwinner-a10"
DEFCONFIG="${3}" # For example "Bananapi_defconfig"
TUPLE="${4}" # For example "arm-linux-gnueabihf"

set -ex

build-u_boot "${DEFCONFIG}" "${TUPLE}"

case "${CHIP_ID}" in
qemu-x86|qemu-x86_64)
	FILE=u-boot.rom
	;;
qemu-arm|qemu-aarch64)
	FILE=u-boot.bin
	;;
*)
	echo "Unknown CHIP_ID \"${CHIP_ID}\""
	exit 1
esac

# Copy U-Boot to 16 sectors from start
dd if=u-boot/"${FILE}" of=tmp.img seek=16 conv=notrunc
